﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Nanohope_v1._0
{
    class MainMenu : GeneralCanvas
    {
        private bool UP, DOWN, ENTER, ESC;
        private KeyboardState keyState;
        private Color color;
        private int state;
        private SpriteFont font;
        private int maxOptions = 4;
        private double previousTime = 0;
        private double delay = 200;

        public MainMenu()
        {
            font = Game1.font;
        }

        public override void gameUpdate(GameTime gameTime)
        {
            this.checkKeys(gameTime);
            changeOption(gameTime.TotalGameTime.TotalMilliseconds);
        }

        private void changeOption(double time)
        {

            if (DOWN && previousTime + delay < time)
            {
                previousTime = time;
                if (this.state + 1 < this.maxOptions)
                {
                    this.state += 1;
                }
                else
                {
                    this.state = 0;
                }
            }
            if (UP && previousTime + delay < time)
            {
                previousTime = time;
                if (this.state > 0)
                {
                    this.state -= 1;
                }
                else
                {
                    this.state = this.maxOptions - 1;
                }
            }
            if (ENTER)
            {
               // System.Diagnostics.Debug.WriteLine(state);
                switch (state)
                {
                    case 0:
                        CanvasManager.instance.newGame();
                        break;
                    case 1:
                        
                        break;
                    case 2:

                        break;
                    case 3:

                        break;
                }
            }
        }

        public override void onDraw(SpriteBatch spriteBatch)
        {
            this.color = Color.White;
            if (this.state == 0)
            {
                this.color = Color.LightGreen;
            }
            spriteBatch.DrawString(font, "New Game", new Vector2(50, 50), this.color);
            this.color = Color.White;
            if (this.state == 1)
            {
                this.color = Color.LightGreen;
            }
            spriteBatch.DrawString(font, "Load Game", new Vector2(50, 80), this.color);
            this.color = Color.White;
            if (this.state == 2)
            {
                this.color = Color.LightGreen;
            }
            spriteBatch.DrawString(font, "Options", new Vector2(50, 110), this.color);
            this.color = Color.White;
            if (this.state == 3)
            {
                this.color = Color.LightGreen;
            }
            spriteBatch.DrawString(font, "Exit", new Vector2(50, 140), this.color);
        }

        protected override void checkKeys(GameTime gameTime)
        {
            keyState = Keyboard.GetState();
            if (keyState.IsKeyDown(Keys.Up))
            {
                UP = true;
            }
            else
            {
                UP = false;
            }
            if (keyState.IsKeyDown(Keys.Down))
            {
                DOWN = true;
            }
            else
            {
                DOWN = false;
            }
            if (keyState.IsKeyDown(Keys.Enter))
            {
                ENTER = true;
            }
            else
            {
                ENTER = false;
            }
            if (keyState.IsKeyDown(Keys.Escape))
            {
                ESC = true;
            }
            else
            {
                ESC = false;
            }
        }
    }
}
